package com.wendy.config;

import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * @author zhuwending
 */
@Configuration
public class ErrorPageConfig {

    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
        return factory -> {
            ErrorPage page404 = new ErrorPage(HttpStatus.NOT_FOUND, "/page/404");
            ErrorPage page403 = new ErrorPage(HttpStatus.FORBIDDEN, "/page/403");
            ErrorPage page500 = new ErrorPage(Exception.class, "/page/500");
            factory.addErrorPages(page404, page403, page500);
        };
    }
}
